/*     */ package com.zimbra.cs.account;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.auth.ZAuthToken;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.auth.AuthMechanism.AuthMech;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpMethod;
/*     */ import org.apache.commons.httpclient.HttpState;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class AuthToken
/*     */ {
/*     */   public static final long DEFAULT_AUTH_LIFETIME = 43200L;
/*     */   
/*     */   public static String generateDigest(String a, String b)
/*     */   {
/*  48 */     if (a == null)
/*  49 */       return null;
/*  50 */     StringBuilder buf = new StringBuilder();
/*  51 */     buf.append(a);
/*  52 */     buf.append(":");
/*  53 */     if (b != null)
/*  54 */       buf.append(b);
/*  55 */     return ByteUtil.getSHA1Digest(buf.toString().getBytes(), true);
/*     */   }
/*     */   
/*     */   public static boolean isAnyAdmin(AuthToken authToken) {
/*  59 */     return (authToken.isAdmin()) || (authToken.isDomainAdmin()) || (authToken.isDelegatedAdmin());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static AuthToken getCsrfUnsecuredAuthToken(AuthToken authToken)
/*     */   {
/*  73 */     if (authToken == null)
/*     */     {
/*     */ 
/*  76 */       return null;
/*     */     }
/*     */     
/*  79 */     if (authToken.isCsrfTokenEnabled()) {
/*     */       try
/*     */       {
/*  82 */         AuthToken token = (AuthToken)authToken.clone();
/*  83 */         token.setCsrfTokenEnabled(false);
/*  84 */         return token;
/*     */       } catch (CloneNotSupportedException e) {
/*  86 */         ZimbraLog.misc.debug("Error cloning auth token.", e);
/*  87 */         return null;
/*     */       }
/*     */     }
/*  90 */     return authToken;
/*     */   }
/*     */   
/*     */ 
/*     */   public abstract String toString();
/*     */   
/*     */   public abstract String getAccountId();
/*     */   
/*     */   public abstract String getAdminAccountId();
/*     */   
/*     */   public abstract long getExpires();
/*     */   
/*     */   public int getValidityValue()
/*     */   {
/* 104 */     return -1;
/*     */   }
/*     */   
/*     */   public abstract void deRegister() throws AuthTokenException;
/*     */   
/*     */   public abstract boolean isRegistered();
/*     */   
/*     */   public abstract boolean isExpired();
/*     */   
/*     */   public abstract boolean isAdmin();
/*     */   
/*     */   public abstract boolean isDomainAdmin();
/*     */   
/*     */   public abstract boolean isDelegatedAdmin();
/*     */   
/*     */   public abstract boolean isZimbraUser();
/*     */   
/*     */   public abstract String getExternalUserEmail();
/*     */   
/*     */   public abstract String getDigest();
/*     */   
/*     */   public abstract String getCrumb() throws AuthTokenException;
/*     */   
/*     */   public boolean isCsrfTokenEnabled() {
/* 128 */     return false;
/*     */   }
/*     */   
/*     */   public void setCsrfTokenEnabled(boolean csrfEnabled) {}
/*     */   
/*     */   public boolean isDelegatedAuth()
/*     */   {
/* 135 */     return (getAdminAccountId() != null) && (!getAdminAccountId().equals(""));
/*     */   }
/*     */   
/*     */   public String getAccessKey() {
/* 139 */     return null;
/*     */   }
/*     */   
/*     */   public AuthMechanism.AuthMech getAuthMech() {
/* 143 */     return null;
/*     */   }
/*     */   
/*     */   public void setProxyAuthToken(String encoded) {}
/*     */   
/* 148 */   public String getProxyAuthToken() { return null; }
/*     */   
/*     */   public void resetProxyAuthToken() {}
/*     */   
/*     */   public Account getAccount() throws ServiceException {
/* 153 */     String acctId = getAccountId();
/* 154 */     Account acct = Provisioning.getInstance().get(Key.AccountBy.id, acctId);
/* 155 */     if (acct == null) {
/* 156 */       throw AccountServiceException.NO_SUCH_ACCOUNT(acctId);
/*     */     }
/* 158 */     return acct;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract void encode(HttpClient paramHttpClient, HttpMethod paramHttpMethod, boolean paramBoolean, String paramString)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public abstract void encode(HttpState paramHttpState, boolean paramBoolean, String paramString)
/*     */     throws ServiceException;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void encode(HttpServletResponse resp, boolean isAdminReq, boolean secureCookie)
/*     */     throws ServiceException
/*     */   {
/* 196 */     encode(resp, isAdminReq, secureCookie, false);
/*     */   }
/*     */   
/*     */   public abstract void encode(HttpServletResponse paramHttpServletResponse, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3)
/*     */     throws ServiceException;
/*     */   
/*     */   public abstract void encodeAuthResp(Element paramElement, boolean paramBoolean)
/*     */     throws ServiceException;
/*     */   
/*     */   public abstract ZAuthToken toZAuthToken()
/*     */     throws ServiceException;
/*     */   
/*     */   public abstract String getEncoded() throws AuthTokenException;
/*     */   
/*     */   public static AuthToken getAuthToken(String encoded) throws AuthTokenException
/*     */   {
/* 212 */     return ZimbraAuthToken.getAuthToken(encoded);
/*     */   }
/*     */   
/*     */   public static AuthToken getAuthToken(String acctId, String externalEmail, String pass, String digest, long expires)
/*     */   {
/* 217 */     return new ZimbraAuthToken(acctId, externalEmail, pass, digest, expires);
/*     */   }
/*     */   
/*     */   public static Map getInfo(String encoded) throws AuthTokenException {
/* 221 */     return ZimbraAuthToken.getInfo(encoded);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/AuthToken.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */